package com.example.administrator.myapplication.View.Fragment;



import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.example.administrator.myapplication.Presenter.LabelPresenter;
import com.example.administrator.myapplication.R;
import com.example.administrator.myapplication.View.layout.LabelItemView;
import com.example.administrator.myapplication.View.layout.MineItemView;

import java.util.HashMap;
import java.util.List;


/**
 * Created by Administrator on 2019/10/13 0013.
 */

public class LabelFragment extends Fragment implements ILabelView{
    private LabelPresenter labelPresenter;
    private LinearLayout ll_root;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_label,container,false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        init(view);
    }
    private void init(View view){
        ll_root = view.findViewById(R.id.ll_root);
        labelPresenter = new LabelPresenter(this);
        labelPresenter.getLabels();
    }

    @Override
    public void showSuccess(String msg) {

    }

    @Override
    public void showError(String msg) {

    }

    @Override
    public void showLables(List<HashMap> labels) {
        for (int i = 0;i < labels.size(); i++){
            HashMap hashMap = labels.get(i);
            ll_root.addView(new LabelItemView(getContext())
                    .init(hashMap.get("thumbnail_path").toString(),hashMap.get("picture_label").toString(),hashMap.get("update_time").toString(),true)
            );

        }
    }
}
